package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.CapBacDto;
import com.tt.fashionWebSite.dto.JsonResponseCode;
import com.tt.fashionWebSite.dto.JsonResponseDto;
import com.tt.fashionWebSite.dto.MauSacDto;
import com.tt.fashionWebSite.service.Ad_ColorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_ColorController {
    @Autowired
    private Ad_ColorService ad_colorService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/registerColor", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminColor(HttpServletRequest request, @RequestBody MauSacDto colorDto) {
        return new JsonResponseDto<Integer>(ad_colorService.adminColor(colorDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/deleteColor", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> deleteColor(HttpServletRequest request, @RequestBody List<MauSacDto> colorDto) {
        return new JsonResponseDto<Integer>(ad_colorService.deleteColor(colorDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllColor", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<MauSacDto>> getAllColor(HttpServletRequest request) {
        return new JsonResponseDto<List<MauSacDto>>(ad_colorService.getAllColor(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductColorPage/{maMau}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageProductColor(HttpServletRequest request, @PathVariable String maMau, Map<String, Object> map) throws ParseException {
        map.put("maMau", maMau);
        return new ModelAndView("admin/ad-product-color-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editProductColor", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<MauSacDto> getColorInfoEdit(HttpServletRequest request, @RequestBody MauSacDto colorDto) {
        return new JsonResponseDto<MauSacDto>(ad_colorService.getColorInfoEdit(colorDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerColorEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<MauSacDto> registerColorEdit(HttpServletRequest request, @RequestBody MauSacDto colorDto) {
        return new JsonResponseDto<MauSacDto>(ad_colorService.registerColorEdit(colorDto), JsonResponseCode.SUCCESS);
    }
}
